<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <title>添加就业信息</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui/css/layui.css">
    <link rel="stylesheet" href="/css/scroll-bar.css">
    <link rel="stylesheet" href="/css/sub-page.css">
</head>
<body>
<div class="ok-body">
    <!--面包屑导航区域-->
    <div class="ok-body-breadcrumb">
            <span class="layui-breadcrumb">
                <a><cite>首页</cite></a>
                <a><cite>就业明星</cite></a>
				<a><cite>添加就业信息</cite></a>
            </span>
        <a class="layui-btn layui-btn-sm" href="javascript:location.replace(location.href);" title="刷新">
            <i class="layui-icon layui-icon-refresh"></i>
        </a>
    </div>
    <!--form表单-->
    <form class="layui-form layui-form-pane ok-form">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-sm9">
                <div class="layui-form-item">
                    <label class="layui-form-label">学生姓名</label>
                    <div class="layui-input-block">
                        <input type="text" name="sname" placeholder="请输入学生姓名"
                               autocomplete="off" class="layui-input" lay-verify="required">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">籍贯</label>
                    <div class="layui-input-block">
                        <input type="text" name="nativePlace" placeholder="请输入籍贯"
                               autocomplete="off" class="layui-input" lay-verify="required">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">专业</label>
                    <div class="layui-input-block">
                        <select name="major">
                            <option value="软件工程">软件工程</option>
                            <option value="视觉传达">视觉传达</option>
                            <option value="电子商务">电子商务</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">就业岗位</label>
                    <div class="layui-input-block">
                        <input type="text" name="station" placeholder="请输入就业岗位"
                               autocomplete="off" class="layui-input" lay-verify="required">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">就业薪资</label>
                    <div class="layui-input-block">
                        <input type="text" name="pay" placeholder="请输入就业薪资"
                               autocomplete="off" class="layui-input" lay-verify="required">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">就业单位</label>
                    <div class="layui-input-block">
                        <input type="text" name="company" placeholder="请输入就业单位"
                               autocomplete="off" class="layui-input" lay-verify="required">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">排序</label>
                    <div class="layui-input-block">
                        <input type="input" class="layui-input" name="sort" value="1">
                    </div>
                </div>
            </div>
            <div class="layui-col-sm3">
                <div class="layui-row cms-photo">
                    <div class="layui-col-sm12">
                        <img id="articleCover" style="width: 100%;height: auto">
                    </div>
                </div>
                <div class="layui-row layui-hide">
                    <input name="photo" type="text" class="layui-input layui-disabled" lay-verify="required" readonly>
                </div>
                <div class="layui-form-item">
                    <button type="button" class="layui-btn" id="uploadImg">
                        <i class="layui-icon">&#xe67c;</i>上传照片
                    </button>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="add">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<!--js逻辑-->
<script src="/lib/jquery/jquery-1.12.4.min.js"></script>
<script src="/lib/layui/layui.js"></script>
<script>
    layui.use(['element', 'form', 'upload'], function () {
        var element = layui.element;
        var form = layui.form;
        let upload = layui.upload;

        //上传图片
        upload.render({
            elem: '#uploadImg' //绑定元素
            , url: '/manage/upload/' //上传接口
            , field: 'upload'
            , size:102485
            ,before: function (obj) {
                layer.load(); //上传loading
            },
            done: function (res) {
                if(res.uploaded) {
                    $('#articleCover').attr("src", res.url);
                    layer.msg('上传成功');
                    $('input[name="photo"]').val(res.url);
                }else{
                    layer.alert(res.error.message)
                }
                layer.closeAll('loading'); //关闭loading
            },
            error: function () {
                layer.closeAll('loading'); //关闭loading
            }

        });

        form.on('submit(add)', function (data) {
            $.ajax({
                url: '/manage/students/',
                data: data.field,
                // contentType:'application/json',
                type: 'POST',
                //dataType: 'json',
                success: function () {
                    layer.msg("添加成功！", {icon: 6, time: 1000, anim: 4}, function () {
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                    });
                },
                error: function () {
                    layer.msg("添加失败")
                }
            });
            return false;
        });
    })
</script>
</body>
</html>
